package jwt

import (
	"fmt"
	"github.com/gin-gonic/gin"
)

func AuthJWt() gin.HandlerFunc {
	return func(c *gin.Context) {
		token := c.GetHeader("token")
		if token == "" {
			c.JSON(400, gin.H{
				"code": 400,
				"msg":  "token不得为空",
			})
			c.Abort()
			return
		}
		userId, err := GetToken(token)
		if err != nil {
			c.JSON(400, gin.H{
				"code": 400,
				"msg":  "失败",
			})
			c.Abort()
			return
		}
		fmt.Println(userId)
		c.Set("userId", userId)
		c.Next()
	}
}
